const app = getApp()
import utils from "../../utils/index";
import {
  userModel,
  fansModel
} from "../../apis/index"

import regeneratorRuntime from '../../libs/wxPromise.min';

Page({
  data: {
    listIndex: 0,
    payprice: 0
  },
  getListIndex(e) {
    let data = utils.getDataSet(e)
    let {
      list
    } = this.data
    this.setData({
      listIndex: data.index,
      payprice: list[data.index].price
    })
  },
  async onLoad(options) {
    utils.showLoading()
    let userInfo = await userModel.getUserInfo()
    let list = await userModel.rechargePriceList()
    this.setData({
      userInfo: userInfo,
      list: list,
      payprice: list[this.data.listIndex].price
    }, () => {
      utils.hideAll()
    })
  },
  async pay() {
    let {
      listIndex,
      list
    } = this.data
    let item = list[listIndex]
    let param = {
      money: item.price,
      star: item.num
    }

    let orderInfo = await userModel.prePayVipStar(param)
    let state = await utils.pay(orderInfo)
    if (state) {
      let show = utils.showModalContent("", '恭喜你,购买成功。', '同意', false)
      if (show) {
        utils.showLoading()
        let userInfo = await userModel.getUserInfo()
        this.setData({
          userInfo: userInfo,
        }, () => {
          utils.hideAll()
        })
      }
    }
  }
})